package io.practice;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Random;
import java.util.Set;

/**
 * 点名：点名名字存储到文本中，读取并点名
 * @author Administrator
 *
 */
public class RollCallDemo {

	// 名单
	private static final ArrayList<String> NAMES; 
	
	static {
		NAMES = new ArrayList<String>();
		
		BufferedReader reader = null;
		try {
			reader = new BufferedReader(new FileReader("name.txt"));
			
			String name = reader.readLine();
			while(name != null) {
				NAMES.add(name);
				name = reader.readLine();
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
	
	
	public static void main(String[] args) {
		
		Random random = new Random();
		Set<Integer> oldName = new HashSet<>();
		
		for (int i=0; i<NAMES.size(); i++) {
			while(true) {
				int index = random.nextInt(NAMES.size());
				if (!oldName.contains(index)) {
					oldName.add(index);
					System.out.println(NAMES.get(index));
					break;
				}
			}
		}
		
		
		
	}
	
	
	
	
	
	
	
	
	
	
	
	
	
}
